/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SaleManager.Category.View;

import SaleManager.Category.Logic.EditCategoryManage;
import SaleManager.View.TableModelFactory;
import data.pojo.Book;
import data.pojo.Category;
import java.util.List;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Kite
 */
public class SearchCategoryPanel extends javax.swing.JPanel {

    /**
     * Creates new form SearchCategoryPanel
     */
    public SearchCategoryPanel() {
        initComponents();
        refreshCategoryTable();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        jTable3.setModel(categoryTable);
        jTable3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable3MouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(jTable3);

        jTable1.setModel(bookTable);
        jScrollPane2.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTable3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable3MouseClicked
        // TODO add your handling code here:

        Category c = ecm.getByIndex(this.jTable3.getSelectedRow());
        if(c.getBookList()!=null)
        refreshBookTable(c.getBookList());
    }//GEN-LAST:event_jTable3MouseClicked

    public void refreshCategoryTable(){
        this.categoryTable.setDataVector(ecm.categoryTableVector(), TableModelFactory.CATEGORY_COLUMN_NAMES);
    }
    
    public void refreshBookTable(List<Book> booklist){
        this.bookTable.setDataVector(ecm.bookTableVector(booklist), TableModelFactory.BOOK_COLUMN_NAMES);
    }
    
    
    private EditCategoryManage ecm = new EditCategoryManage();
    private DefaultTableModel categoryTable = TableModelFactory.getCategoryModel();  
    private DefaultTableModel bookTable = TableModelFactory.getAddBookModel();  
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable3;
    // End of variables declaration//GEN-END:variables
}
